package vesion2.barrier.spec;

import com.fasterxml.jackson.annotation.JsonIgnore;
import vesion2.barrier.Barrier;
import vesion2.barrier.Iron;
import vesion2.barrier.ProtectLimit;
import vesion2.object.Point;
import vesion2.object.Rectangle;
import vesion2.tank.BaseTank;
import vesion2.tank.EnemyTank;

import java.util.ArrayList;
import java.util.Vector;

public class BornPlace{
    private Point point;
    //0--自己，1敌人
    private int type;
    private int id;

    @JsonIgnore
    private  Vector<EnemyTank> tanks;

    public BornPlace(Point point,int type,int id){
        this.point=point;
        this.type=type;
        this.id=id;
    }
    public BornPlace(){
    }

    public void addHome(Vector<Barrier> barriers){
        barriers.add(new Iron(point,21,21));
        barriers.add(new ProtectLimit(new Point(point.getX()+20,point.getY()),51,21,type));
        barriers.add(new Iron(new Point(point.getX()+70, point.getY()),21,21));
        barriers.add(new ProtectLimit(new Point(point.getX(),point.getY()+20),21,51,type));
        barriers.add(new ProtectLimit(new Point(point.getX()+70,point.getY()+20),21,51,type));
        barriers.add(new Iron(new Point(point.getX(),point.getY()+70),21,21));
        barriers.add(new ProtectLimit(new Point(point.getX()+20,point.getY()+70),51,21,type));
        barriers.add(new Iron(new Point(point.getX()+70, point.getY()+70),21,21));
    }

    public Point getPoint() {
        return point;
    }

    public void setPoint(Point point) {
        this.point = point;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @JsonIgnore
    public void setTanks(Vector<EnemyTank> tanks){this.tanks=tanks;}

    public boolean canUse(){
        for(int i=0;i<tanks.size();i++)
        {
            BaseTank baseTank = tanks.get(i);
            if(baseTank.isIntersect(new Rectangle(new Point(point.getX()+21,point.getY()+21),51,51)))
                return false;
        }
        return true;
    }
    @JsonIgnore
    public Point getTankPoint(){
        return new Point(point.getX()+24,point.getY()+21);
    }

    @Override
    public String toString() {
        return "BornPlace{" +
                "point=" + point +
                ", type=" + type +
                '}';
    }
}
